package Eyjafjalla.card.attack;

import Eyjafjalla.action.EyjafjallaAttackAction;
import Eyjafjalla.card.AbstractEyjafjallaCard;
import Eyjafjalla.card.status.Burn_Eyjafjalla;
import Eyjafjalla.panel.CloudEnergyPanel;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.MakeTempCardInDiscardAction;
import com.megacrit.cardcrawl.actions.common.MakeTempCardInHandAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.VulnerablePower;
import com.megacrit.cardcrawl.ui.panels.EnergyPanel;

public class FlameBurst_Eyjafjalla extends AbstractEyjafjallaCard {
    public static final String ID = "FlameBurst_Eyjafjalla";
    private static final CardStrings cardStrings;

    public FlameBurst_Eyjafjalla(){
        super(ID, cardStrings.NAME,0,cardStrings.DESCRIPTION,CardType.ATTACK,CardRarity.UNCOMMON,CardTarget.ENEMY);
        this.baseDamage = 6;
        this.damage =6;
        this.baseMagicNumber = 0;
        this.magicNumber = 0;
        cardsToPreview = new Burn_Eyjafjalla();
        setFireDescription(cardStrings.EXTENDED_DESCRIPTION[0]);
    }

    @Override
    public AbstractCard makeCopy() {
        return new FlameBurst_Eyjafjalla();
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(new EyjafjallaAttackAction());
        for(int i =0;i<this.magicNumber+1;i++)
            addToBot(new DamageAction(m,new DamageInfo(p,damage,damageTypeForTurn), AbstractGameAction.AttackEffect.FIRE));

        addToBot(new MakeTempCardInDiscardAction(getUpgradeCard(this.magicNumber),1));
    }

    private AbstractCard getUpgradeCard(int amt){
        AbstractCard c = new Burn_Eyjafjalla();
        for(int i =0;i<amt;i++){
            c.upgrade();
        }
        return c;
    }

    @Override
    public void applyPowers() {
        int trueM = baseMagicNumber;
        baseMagicNumber = EnergyPanel.getCurrentEnergy() + CloudEnergyPanel.getCurrentEnergy();
        magicNumber = baseMagicNumber;
        baseMagicNumber = trueM;
        isMagicNumberModified = baseMagicNumber!=magicNumber;

        int trueD = baseDamage;
        if(isFire()){
            baseDamage+=2;
        }
        super.applyPowers();
        baseDamage = trueD;
        isDamageModified = baseDamage!=damage;
    }

    @Override
    public void calculateCardDamage(AbstractMonster mo) {
        int trueD = baseDamage;
        if(isFire()){
            baseDamage+=2;
        }
        super.calculateCardDamage(mo);
        baseDamage = trueD;
        isDamageModified = baseDamage!=damage;
    }

    @Override
    public void upgrade() {
        if(!this.upgraded){
            upgradeName();
            upgradeDamage(2);
        }
    }

    static {
        cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    }
}


